package com.imooc.service.impl;

import com.imooc.mapper.CategoryCustomMapper;
import com.imooc.mapper.CategoryMapper;
import com.imooc.pojo.Category;
import com.imooc.pojo.vo.CategoryVo;
import com.imooc.pojo.vo.NewItemsVo;
import com.imooc.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Autowired
    private CategoryCustomMapper categoryCustomMapper;


    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<Category> queryAllCat1(Integer type,Integer father_id) {

        Example example=new Example(Category.class);
        Example.Criteria criteria=example.createCriteria();

        criteria.andEqualTo("type",type);
        criteria.andEqualTo("fatherId",father_id);

        List<Category> list=categoryMapper.selectByExample(example);

        return list;
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<CategoryVo> queryAllsubCat(Integer father_id) {

        List<CategoryVo> list=categoryCustomMapper.queryAllsubCat(father_id);

        return list;
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<NewItemsVo> getSixNewItemsLazy(Integer rootCatId) {

        Map<String,Object> map=new HashMap<>();
        map.put("rootCatId",rootCatId);

        return categoryCustomMapper.getSixNewItemsLazy(map);
    }
}
